using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPCoco;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ParticlesDemo.Scenes
{
    public class DemoScene : Scene
    {
        static SpriteFont debugFont;
        static SpriteFont titleFont;

        static DemoScene()
        {
            debugFont = Coco.Load<SpriteFont>("DebugFont");
            titleFont = Coco.Load<SpriteFont>("TitleFont");
        }

        public DemoScene()
        {
            lblTitle = new SpriteFontLabel(titleFont);
            lblTitle.Position = new Vector2(Screen.Width / 2, 30);
            lblTitle.Anchor = new Vector2(0.5f);
            lblTitle.DropShadow = true;
            AddNode(lblTitle, 2);
            Title = "Title";

            BackNextControl ctrl = new BackNextControl();
            ctrl.Position = new Vector2(0, Screen.Height - ctrl.Height);
            AddNode(ctrl, 2);
        }

        SpriteFontLabel lblTitle;

        public string Title { get { return lblTitle.Text; } set { lblTitle.Text = value; } }

        double frames = 0, elapsed = 0;
        string text = string.Empty;

        public override void SelfDraw(GameTime gameTime)
        {
            frames++;
            elapsed += gameTime.ElapsedGameTime.TotalSeconds;
            if (elapsed > 0.5)
            {
                text = string.Format("FPS {0}", (int)(frames / elapsed));
                elapsed = 0;
                frames = 0;
            }

            CachedSpriteBatch batch = SpriteBatchCache.GetVolatile();
            batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, WorldMatrix.Shared.CurrentMatrix);
            batch.DrawString(debugFont, text, new Vector2(10, Screen.Height - 30), Color.Red);
            batch.End();
        }
    }
}
